package com.hcg.distributedtx.common.function;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局捕获异常
 * 捕获异常返回 json 格式
 * 捕捉返回页面
 */
@RestControllerAdvice(basePackages = {"com.hcg.distributedtx"})
public class GrobalExceptionHandler {

    /**
     * TODO
     * 获取错误信息
      */

    @ResponseBody
    @ExceptionHandler(RuntimeException.class)
    public Map<String,Object> errorResult(){
        Map<String,Object> map = new HashMap<>();
        map.put("errorCode","500");
        map.put("errorMsg", errorResult().toString());
        return  map;
    }

}
